package com.hmy.contract.manager.uaa;

import com.hmy.ccp.common.result.FeignResult;
import com.hmy.uaa.api.bo.request.DataDictionaryRequest;
import com.hmy.uaa.api.bo.response.DataDictionaryResponse;
import com.hmy.uaa.api.client.dictionary.DataDictionaryClient;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
public class DataDictionaryRpc {

    @Resource
    private DataDictionaryClient dataDictionaryClient;

    /**
     * 根据nodeKey查询数据字典值
     *
     * @param nodeKey 节点key
     * @return 数据字典值
     */
    public Map<String, String> queryNodeLabel(String nodeKey) {
        DataDictionaryRequest req = new DataDictionaryRequest();
        req.setNodeKey(nodeKey);
        FeignResult<List<DataDictionaryResponse>> re = dataDictionaryClient.getDictionariesByNodeKey(req);
        return re.getData().stream().collect(Collectors.toMap(DataDictionaryResponse::getValue,
                DataDictionaryResponse::getLabel, (key1, key2) -> key2));
    }

    /**
     * 根据nodeKey查询数据字典值
     *
     * @param nodeKey 节点key
     * @return 数据字典值
     */
    public Map<String, String> queryCssTag(String nodeKey) {
        DataDictionaryRequest req = new DataDictionaryRequest();
        req.setNodeKey(nodeKey);
        FeignResult<List<DataDictionaryResponse>> re = dataDictionaryClient.getDictionariesByNodeKey(req);
        return re.getData().stream().collect(Collectors.toMap(DataDictionaryResponse::getValue,
                DataDictionaryResponse::getCssTag, (key1, key2) -> key2));
    }


}
